package org.lim.aiagent.rag.nativeMDRag.load;

import jakarta.annotation.Resource;
import org.lim.aiagent.rag.nativeMDRag.extract.PsychologicalAppDocumentLoader;
import org.lim.aiagent.rag.nativeMDRag.transformer.MyKeywordEnricher;
import org.springframework.ai.document.Document;
import org.springframework.ai.document.DocumentTransformer;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class PsychologicalAppVectorStoreConfig {

    @Resource
    private PsychologicalAppDocumentLoader psychologicalAppDocumentLoader;
    @Resource
    private DocumentTransformer tokenTextSplitter;
    @Resource
    private MyKeywordEnricher myKeywordEnricher;
    
    @Bean
    VectorStore psychologicalAppVectorStore(EmbeddingModel dashscopeEmbeddingModel) {
        SimpleVectorStore simpleVectorStore = SimpleVectorStore.builder(dashscopeEmbeddingModel)
                .build();
        // 加载文档
        List<Document> documents = psychologicalAppDocumentLoader.loadMarkdowns();
        // 2. **【新增步骤】** 使用 Transformer 对文档进行精细分割
        //不建议使用token text splitter
//        List<Document> transformedDocs = tokenTextSplitter.transform(documents);
        // 使用自定义的 KeywordEnricher 对文档进行关键词提取,AI自动解析关键词到原信息
//        List<Document> transformedDocs = myKeywordEnricher.enrichDocuments(documents);
        simpleVectorStore.add(documents);
        return simpleVectorStore;
    }
}
